package com.hnhp.controller;

import com.hnhp.dto.ResponseDTO;
import com.hnhp.model.Category;
import com.hnhp.model.CategoryQuery;
import com.hnhp.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.util.List;

@RestController
@RequestMapping("/api/category")
@CrossOrigin
public class CategoryController {

    //引入service
    @Autowired
    private CategoryService service;

    @GetMapping("/find")
//    public List<Category> findAll(){
//        List<Category> list = service.findAll();
//        return list;
//    }
    public ResponseDTO findAll(){
        List<Category> list = service.findAll();
        return ResponseDTO.success(list);
    }

    @GetMapping
    public List<Category> select(CategoryQuery query){
        List<Category> categoryList = service.select(query);
        return categoryList;
    }
    @PostMapping
    public Integer insert(@RequestBody Category category){
        return service.insert(category);
    }
    @PutMapping
    public Integer update(@RequestBody Category category){
        return service.update(category);
    }
    // 软删除
    @DeleteMapping
    public Integer updateStatus(Integer id){
        return service.updateStatus(id);
    }
}
